package cn.cmcc.online.smsapi.ui.view;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.json.JSONObject;

import cn.cmcc.online.smsapi.ui.presenter.EmailPresenter;
import cn.cmcc.online.smsapi.ui.presenter.EmailPresenterImpl;
import cn.cmcc.online.smsapi.ui.util.DensityUtil;
import cn.cmcc.online.smsapi.ui.widget.SpotDivier;

/**
 * Created by ZhangYifan on 2017/6/17.
 */

public class EmailVistaImpl extends GeneralBaseVistaImpl implements EmailVista {
    private EmailPresenter mPresenter;

    private TextView mSender;
    private TextView mEmailContent;
    private TextView mActivitiesInfo;

    public EmailVistaImpl(Context context) {
        super(context);
    }

    @Override
    protected void init() {
        super.init();
        mPresenter = new EmailPresenterImpl();
        mPresenter.setVista(this);
    }

    @Override
    protected void initLayout() {
        super.initLayout();

        LinearLayout body = new LinearLayout(mContext);
        body.setOrientation(LinearLayout.VERTICAL);
        body.setBackgroundColor(Color.WHITE);
        body.setPadding(0,0,0,DensityUtil.dp2px(mContext,15));
        body.setLayoutParams(new LinearLayout.LayoutParams(DensityUtil.dp2px(mContext, 300), -2));
        //----------------------------------------------------------------
        mSender = new TextView(mContext);
        mSender.setTextColor(Color.parseColor("#333333"));
        mSender.setTextSize(14);
//        mSender.setText("发件人:张一凡");
        LinearLayout.LayoutParams addresserParams = new LinearLayout.LayoutParams(-2, -2);
        addresserParams.setMargins(DensityUtil.dp2px(mContext, 15), DensityUtil.dp2px(mContext, 15), DensityUtil.dp2px(mContext, 15), DensityUtil.dp2px(mContext, 20));
        body.addView(mSender, addresserParams);
        //----------------------------------------------------------------
        mEmailContent = new TextView(mContext);
        mEmailContent.setTextColor(Color.parseColor("#666666"));
        mEmailContent.setTextSize(12);
        LinearLayout.LayoutParams contentParams = new LinearLayout.LayoutParams(-2, -2);
        contentParams.setMargins(DensityUtil.dp2px(mContext, 15), 0, DensityUtil.dp2px(mContext, 15), 0);
        body.addView(mEmailContent, contentParams);
        //----------------------------------------------------------------
        View divier = new SpotDivier(mContext);
        LinearLayout.LayoutParams divierParams = new LinearLayout.LayoutParams(-1, DensityUtil.dp2px(mContext, 2));
        divierParams.setMargins(0, DensityUtil.dp2px(mContext, 15), 0, 0);
        body.addView(divier, divierParams);
        //----------------------------------------------------------------
        mActivitiesInfo = new TextView(mContext);
        mActivitiesInfo.setTextColor(Color.parseColor("#999999"));
        mActivitiesInfo.setTextSize(12);
        LinearLayout.LayoutParams activitiesParams = new LinearLayout.LayoutParams(-2, -2);
        activitiesParams.setMargins(DensityUtil.dp2px(mContext, 15), DensityUtil.dp2px(mContext, 15), DensityUtil.dp2px(mContext, 15), 0);
        body.addView(mActivitiesInfo, activitiesParams);

        super.addBody(body);
    }

    @Override
    public void bind(Context context, JSONObject data) {
        super.bind(context, data);
        mPresenter.bind(data);
    }

    @Override
    public void initDefaultView() {
        super.initDefaultView();
    }

    @Override
    public void setSender(String sender) {
        mSender.setText(sender);
    }

    @Override
    public void setEmailContent(String emailContent) {
        mEmailContent.setText(emailContent);
    }

    @Override
    public void setEmailContentVisible(int visible) {
        mEmailContent.setVisibility(visible);
    }

    @Override
    public void setTipInfo(String activitiesInfo) {
        mActivitiesInfo.setText(activitiesInfo);
    }

    @Override
    public void setTipInfoVisible(int visible) {
        mActivitiesInfo.setVisibility(visible);
    }
}
